package cn.wolfcode.trip.web.controller;

import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.domain.TravelContent;
import cn.wolfcode.trip.base.query.TravelQueryObject;
import cn.wolfcode.trip.base.service.ITravelService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/travel")
public class TravelController {
    @Autowired
    private ITravelService service;


    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") TravelQueryObject qo) {
        qo.setOrderBy("lastUpdateTime");
        PageInfo<Travel> pageInfo = service.selectForList(qo);
        model.addAttribute("result",pageInfo);
        return "travel/list";
    }
    @RequestMapping("/content")
    @ResponseBody
    public Object getContent(Long id){
       TravelContent content = service.getContentById(id);
       return content;
    }
    @RequestMapping("/update")
    @ResponseBody
    public Object updateState(Travel travel){
        JSONResult json = new JSONResult();
        try {
            service.updateState(travel);
        } catch (Exception e) {
            e.printStackTrace();
            json.mark("操作失败");
        }
        return json;
    }
}
